package com.rjgc.title.controller.apply;

import com.rjgc.title.common.result.Result;
import com.rjgc.title.model.entity.apply.*;
import com.rjgc.title.model.entity.student.LearningExperience;
import com.rjgc.title.model.entity.user.CurrentTitle;
import com.rjgc.title.model.entity.user.UserInfo;
import com.rjgc.title.service.*;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;


import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.util.HashMap;
import java.util.List;

/**
 * @program: title-parent
 * @author: Mr.Zhuo
 * @create: 2022-04-26 11:24
 **/

@Api(tags = "生成pdf所需要的数据 ")
@RestController
@RequestMapping("/api/pdf")
public class GeneratePDFController {

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private CurrentTitleService currentTitleService;

    @Autowired
    private LearningExperienceService learningExperienceService;

    @Autowired
    private TeachAwardsService teachAwardsService;

    @Autowired
    private PaperService paperService;

    @Autowired
    private AwardTutoringStudentsService awardTutoringStudentsService;

    @Autowired
    private AchievementsService achievementsService;

    @Autowired
    private UnifiedPlanningService unifiedPlanningService;

    @Autowired
    private WorkService workService;

    @Autowired
    private EducationProjectService educationProjectService;

    @Autowired
    private ResearchProjectService researchProjectService;

    @Autowired
    private AutobiographyService autobiographyService;


    @GetMapping("inner/createIndex")
    public Result createIndex(HttpServletRequest request) {
        // 获取用户列表
        String userId = (String) request.getSession().getAttribute("userId");

        // 设置模板的内容
        Context context = new Context();
        // 获取个人信息
        UserInfo userInfo = userInfoService.getUserInfo(userId);
        // 获取现任职称
        CurrentTitle currentTitle = currentTitleService.getCurrentTitle(userId);
        // 学习经历
        List<LearningExperience> learningExperiences = learningExperienceService.getLearningExperience(userId);
        // 教育教学获奖情况
        List<TeachAwards> teachAwardsList = teachAwardsService.getAll(userId);
        // 论文
        List<Paper> paperList = paperService.getAll(userId);
        // 辅导学生作业
        List<AwardTutoringStudents> awardTutoringStudentsList = awardTutoringStudentsService.getAll(userId);
        // 成果
        List<Achievements> achievementsList = achievementsService.getAll(userId);
        //统编规划教材
        List<UnifiedPlanning> unifiedPlanningList = unifiedPlanningService.getAll(userId);
        // 著作
        List<Work> workList = workService.getAll(userId);
        // 教育教学项目
        List<EducationProject> educationProjectList = educationProjectService.getAll(userId);
        // 科研项目
        List<ResearchProject> researchProjectList = researchProjectService.getAll(userId);
        // 个人自传
        Autobiography autobiography = autobiographyService.getAll(userId);
        //传输数据
        HashMap<String, Object> map = new HashMap<>();
        map.put("userInfo", userInfo);
        map.put("currentTitle", currentTitle);
        map.put("learningExperiences", learningExperiences);
        map.put("teachAwardsList", teachAwardsList);
        map.put("paperList", paperList);
        map.put("awardTutoringStudentsList", awardTutoringStudentsList);
        map.put("achievementsList", achievementsList);
        map.put("unifiedPlanningList", unifiedPlanningList);
        map.put("workList", workList);
        map.put("educationProjectList", educationProjectList);
        map.put("researchProjectList", researchProjectList);
        map.put("autobiography", autobiography);

        return Result.ok(map);
    }


}
